package emotion_codesoe_com

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/emotion_codesoe_com"
	emotion_codesoe_comReq "github.com/flipped-aurora/gin-vue-admin/server/model/emotion_codesoe_com/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type OsMenuApi struct {
}

var osMenuService = service.ServiceGroupApp.Emotion_codesoe_comServiceGroup.OsMenuService

// CreateOsMenu 创建osMenu表
// @Tags OsMenu
// @Summary 创建osMenu表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body emotion_codesoe_com.OsMenu true "创建osMenu表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /osMenu/createOsMenu [post]
func (osMenuApi *OsMenuApi) CreateOsMenu(c *gin.Context) {
	var osMenu emotion_codesoe_com.OsMenu
	err := c.ShouldBindJSON(&osMenu)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := osMenuService.CreateOsMenu(&osMenu); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteOsMenu 删除osMenu表
// @Tags OsMenu
// @Summary 删除osMenu表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body emotion_codesoe_com.OsMenu true "删除osMenu表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /osMenu/deleteOsMenu [delete]
func (osMenuApi *OsMenuApi) DeleteOsMenu(c *gin.Context) {
	id := c.Query("ID")
	if err := osMenuService.DeleteOsMenu(id); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteOsMenuByIds 批量删除osMenu表
// @Tags OsMenu
// @Summary 批量删除osMenu表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除osMenu表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /osMenu/deleteOsMenuByIds [delete]
func (osMenuApi *OsMenuApi) DeleteOsMenuByIds(c *gin.Context) {
	ids := c.QueryArray("ids[]")
	if err := osMenuService.DeleteOsMenuByIds(ids); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateOsMenu 更新osMenu表
// @Tags OsMenu
// @Summary 更新osMenu表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body emotion_codesoe_com.OsMenu true "更新osMenu表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /osMenu/updateOsMenu [put]
func (osMenuApi *OsMenuApi) UpdateOsMenu(c *gin.Context) {
	var osMenu emotion_codesoe_com.OsMenu
	err := c.ShouldBindJSON(&osMenu)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := osMenuService.UpdateOsMenu(osMenu); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindOsMenu 用id查询osMenu表
// @Tags OsMenu
// @Summary 用id查询osMenu表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query emotion_codesoe_com.OsMenu true "用id查询osMenu表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /osMenu/findOsMenu [get]
func (osMenuApi *OsMenuApi) FindOsMenu(c *gin.Context) {
	id := c.Query("ID")
	if reosMenu, err := osMenuService.GetOsMenu(id); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reosMenu": reosMenu}, c)
	}
}

// GetOsMenuListPage 分页获取osMenu表列表
// @Tags OsMenu
// @Summary 分页获取osMenu表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query emotion_codesoe_comReq.OsMenuSearch true "分页获取osMenu表列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /osMenu/getOsMenuList [get]
func (osMenuApi *OsMenuApi) GetOsMenuListPage(c *gin.Context) {
	var pageInfo emotion_codesoe_comReq.OsMenuSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := osMenuService.GetOsMenuInfoListPage(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetOsMenuList 分页获取osMenu表列表
// @Tags OsMenu
// @Summary 分页获取osMenu表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query emotion_codesoe_comReq.OsMenuSearch true "分页获取osMenu表列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /osMenu/getOsMenuList [get]
func (osMenuApi *OsMenuApi) GetOsMenuList(c *gin.Context) {
	var pageInfo emotion_codesoe_comReq.OsMenuSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, err := osMenuService.GetOsMenuInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(gin.H{"list": list}, "获取成功", c)
	}
}
